package com.bdv.md.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table (name = "REM_TBL")
@DynamicInsert
@DynamicUpdate
public class RemTbl extends BaseObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7L;
	
	private String txId;
	private String remote;
	private MapTbl mapTbl;

	public RemTbl(){
	}
	
	public RemTbl(String txId, String remote, Integer mapTblId) {
		this.txId = txId;
		this.remote = remote;
		this.mapTbl = new MapTbl(mapTblId);
	}

	@Id
	@Column(name = "TX_ID")
	public String getTxId() {
		return txId;
	}
	public void setTxId(String txId) {
		this.txId = txId;
	}
	
	@Column(name = "REMOTE")
	public String getRemote() {
		return remote;
	}
	public void setRemote(String remote) {
		this.remote = remote;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MAP_ID", nullable = false)
	public MapTbl getMapTbl() {
		return mapTbl;
	}
	public void setMapTbl(MapTbl mapTbl) {
		this.mapTbl = mapTbl;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((mapTbl == null) ? 0 : mapTbl.hashCode());
		result = prime * result + ((remote == null) ? 0 : remote.hashCode());
		result = prime * result + ((txId == null) ? 0 : txId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RemTbl other = (RemTbl) obj;
		if (mapTbl == null) {
			if (other.mapTbl != null)
				return false;
		} else if (!mapTbl.equals(other.mapTbl))
			return false;
		if (remote == null) {
			if (other.remote != null)
				return false;
		} else if (!remote.equals(other.remote))
			return false;
		if (txId == null) {
			if (other.txId != null)
				return false;
		} else if (!txId.equals(other.txId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "RemTbl [" + (txId != null ? "txId=" + txId + ", " : "")
				+ (remote != null ? "remote=" + remote + ", " : "")
				+ (mapTbl != null ? "mapTbl=" + mapTbl : "") + "]";
	}
	
	
	
}
